package com.fyt.recover.order;

import java.util.Arrays;

public class CountingSortStartWithZero {

    public static void CountingSort(int[] arr) {

        int max= Arrays. stream(arr).max().orElse(0);
      

        int [] count=new int [max+1];
        
        for(int num:arr){
            count[num]++;

        }
      int index=0;
        for (int i = 0; i <=max ; i++) {
            while (count[i]>0){
                arr[index]=i;
                count[i]--;
                index++;
            }
        }

        System.out.println(Arrays.toString(arr));
    }

}
